package jzOffer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Num34 {
    List<List<Integer>> res=new ArrayList<>();
    LinkedList<Integer> path=new LinkedList<>();
    public List<List<Integer>> pathSum(TreeNode root, int target) {
        recur(root,target);
        return res;
    }
    private void recur(TreeNode root,int target){
        if(root==null) return;
        path.add(root.val);
        target-=root.val;
        if(root.left==null && root.right==null && target==0){
            res.add(new LinkedList(path));
        }
        recur(root.left,target);
        recur(root.right,target);
        path.removeLast();
    }
}
